package com.ecloud.arithmetic.controller;

import com.ecloud.arithmetic.dto.*;
import com.ecloud.arithmetic.entities.*;
import com.ecloud.arithmetic.service.*;
import com.ecloud.common.JsonResult;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * @author Squbi
 * @date 2021/7/28 15:23
 */
@Api("功耗相关接口")
@RestController
public class EnergyController {
    @Autowired
    EnergyPredictionService predictionService;
    @Autowired
    EnergyTopService topService;
    @Autowired
    EnergyTotalService totalService;
    @Autowired
    EnergyIndicatorsDailyService dailyService;
    @Autowired
    EnergyIndicatorsMonthService monthService;

    @PostMapping("/arithmetic/energy/prediction")
    @ApiOperation("新增功耗预测信息")
    public JsonResult insertEnergyPrediction(@RequestBody EnergyPredictionDto dto) {
        predictionService.insert(dto);
        return JsonResult.success();
    }

    @ApiOperation("新增功耗排名信息")
    @PostMapping("/arithmetic/energy/top")
    public JsonResult insertEnergyTop(@RequestBody EnergyTopDto dto) {
        topService.insert(dto);
        return JsonResult.success();
    }

    @ApiOperation("新增功耗统计信息")
    @PostMapping("/arithmetic/energy/total")
    public JsonResult insertEnergyTotal(@RequestBody EnergyTotalDto dto) {
        totalService.insert(dto);
        return JsonResult.success();
    }

    @ApiOperation("获取功耗预测信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "buildingName", value = "建筑名称", required = false),
            @ApiImplicitParam(name = "dataType", value = "数据类型 0为全部 1为预测 2为实际", required = true),
            @ApiImplicitParam(name = "startTime", value = "开始时间 时间格式 yyyy-MM-dd HH:mm:ss", required = false),
            @ApiImplicitParam(name = "endTime", value = "结束时间 时间格式 yyyy-MM-dd HH:mm:ss", required = false),
            @ApiImplicitParam(name = "pageIndex", value = "分页页码 最小为1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页大小 最小为1", required = true)
    })
    @GetMapping("/arithmetic/energy/prediction")
    public JsonResult selectEnergyPrediction(@Validated EnergyPredictionSelectDto dto) {
        List<EnergyPrediction> data = predictionService.select(dto);
        return JsonResult.success(data);
    }

    @ApiOperation("获取功耗排名信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "startTime", value = "开始时间 时间格式 yyyy-MM-dd HH:mm:ss", required = false),
            @ApiImplicitParam(name = "endTime", value = "结束时间 时间格式 yyyy-MM-dd HH:mm:ss", required = false),
            @ApiImplicitParam(name = "pageIndex", value = "分页页码 最小为1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页大小 最小为1", required = true)
    })
    @GetMapping("/arithmetic/energy/top")
    public JsonResult selectEnergyTop(@Validated EnergyTopSelectDto dto) {
        List<EnergyTop> data = topService.select(dto);
        return JsonResult.success(data);
    }

    @ApiOperation("获取功耗统计信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "buildingName", value = "建筑名称", required = false),
            @ApiImplicitParam(name = "dataType", value = "数据类型 0为全部 1为办公总量 2为空调总量", required = true),
            @ApiImplicitParam(name = "startTime", value = "开始时间 时间格式 yyyy-MM-dd HH:mm:ss", required = false),
            @ApiImplicitParam(name = "endTime", value = "结束时间 时间格式 yyyy-MM-dd HH:mm:ss", required = false),
            @ApiImplicitParam(name = "pageIndex", value = "分页页码 最小为1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页大小 最小为1", required = true)
    })
    @GetMapping("/arithmetic/energy/total")
    public JsonResult selectEnergyTotal(@Validated EnergyTotalSelectDto dto) {
        List<EnergyTotal> data = totalService.select(dto);
        return JsonResult.success(data);
    }

    @ApiOperation("新增每日能量指标信息")
    @PostMapping("/arithmetic/energy/indicators/daily")
    public JsonResult insertEnergyIndicatorsDaily(@RequestBody EnergyIndicatorsDailyDto dto) {
        dailyService.insert(dto);
        return JsonResult.success();
    }

    @ApiOperation("新增每月能量指标信息")
    @PostMapping("/arithmetic/energy/indicators/month")
    public JsonResult insertEnergyIndicatorsMonth(@RequestBody EnergyIndicatorsMonthDto dto) {
        monthService.insert(dto);
        return JsonResult.success();
    }

    @ApiOperation("获取每日能量指标信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "buildingName", value = "建筑名称", required = false),
            @ApiImplicitParam(name = "dataType", value = "数据类型 0:全部 1:data真实值 2:up_line上轨线 3:mean_data移动平均线", required = true),
            @ApiImplicitParam(name = "calculateType", value = "计算类型 0:全部 1:累计 2:当天", required = true),
            @ApiImplicitParam(name = "startTime", value = "开始时间 时间格式 yyyy-MM-dd HH:mm:ss", required = false),
            @ApiImplicitParam(name = "endTime", value = "结束时间 时间格式 yyyy-MM-dd HH:mm:ss", required = false),
            @ApiImplicitParam(name = "pageIndex", value = "分页页码 最小为1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页大小 最小为1", required = true)
    })
    @GetMapping("/arithmetic/energy/indicators/daily")
    public JsonResult selectEnergyIndicatorsDaily(@Validated EnergyIndicatorsDailySelectDto dto) {
        List<EnergyIndicatorsDaily> data = dailyService.select(dto);
        return JsonResult.success(data);
    }

    @ApiOperation("获取每月能量指标信息")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "buildingName", value = "建筑名称", required = false),
            @ApiImplicitParam(name = "dataType", value = "数据类型 0:全部 1:data真实值 2:up_line上轨线 3:mean_data移动平均线", required = true),
            @ApiImplicitParam(name = "calculateType", value = "计算类型 0:全部 1:累计 2:当月", required = true),
            @ApiImplicitParam(name = "startTime", value = "开始时间 时间格式 yyyy-MM-dd HH:mm:ss", required = false),
            @ApiImplicitParam(name = "endTime", value = "结束时间 时间格式 yyyy-MM-dd HH:mm:ss", required = false),
            @ApiImplicitParam(name = "pageIndex", value = "分页页码 最小为1", required = true),
            @ApiImplicitParam(name = "pageSize", value = "分页大小 最小为1", required = true)
    })
    @GetMapping("/arithmetic/energy/indicators/month")
    public JsonResult selectEnergyIndicatorsMonth(@Validated EnergyIndicatorsMonthSelectDto dto) {
        List<EnergyIndicatorsMonth> data = monthService.select(dto);
        return JsonResult.success(data);
    }
}
